﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WuDada.Core.Post;
using WuDada.Core.Post.Service;
using WuDada.Core.Post.Domain;
using System.Text;

public partial class UserControl_LeftService : System.Web.UI.UserControl
{
    private PostFactory m_PostFactory;
    private IPostService m_PostService;

    //服務項目 m_NodeId = 16
    private readonly int m_NodeId = 16;

    protected void Page_Load(object sender, EventArgs e)
    {
        m_PostFactory = new PostFactory();
        m_PostService = m_PostFactory.GetPostService();

        if (!IsPostBack)
        {
            FillService();
        }
    }

    private void FillService()
    {
        IList<NodeVO> subNodeList = m_PostService.GetNodeListByParentId(16);
        RepeaterService.DataSource = subNodeList;
        RepeaterService.DataBind();
    }

    protected void RepeaterService_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemIndex != -1)
        {
            Control ctrl = e.Item;
            NodeVO nodeVO = (NodeVO)e.Item.DataItem;

            ////子項目
            StringBuilder sbIndications = new StringBuilder();
            Dictionary<string, string> conditions = new Dictionary<string, string>();
            conditions.Add("NodeId", nodeVO.NodeId.ToString());
            conditions.Add("Flag", "1");
            IList<PostVO> list = m_PostService.GetPostList(conditions);

            if (list != null && list.Count > 0)
            {
                foreach (PostVO postVO in list)
                {
                    sbIndications.AppendFormat("<a href='service_in.aspx?id={0}'><li class='service-li2'>{1}</li></a>"
                        , postVO.PostId, postVO.Title);
                }
            }

            UIHelper.SetLiteralText(ctrl, "ltlSub", sbIndications.ToString());
        }
    }
}